home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue64 / WBroker / Viewform.pas < prev   
Encoding:
Pascal/Delphi Source File  |  2000-09-17  |  2.7 KB  |  106 lines

  1. unit Viewform;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, StdCtrls, Buttons, ExtCtrls, Printers, HTTPApp;
  8.  
  9. type
  10.   TCCForm = class(TForm)
  11.     Memo1: TMemo;
  12.     Panel1: TPanel;
  13.     BitBtn1: TBitBtn;
  14.     BitBtn2: TBitBtn;
  15.     Edit1: TEdit;
  16.     Label1: TLabel;
  17.     Edit2: TEdit;
  18.     Label2: TLabel;
  19.     BitBtn3: TBitBtn;
  20.     ComboBox1: TComboBox;
  21.     Label3: TLabel;
  22.     ComboBox2: TComboBox;
  23.     Label4: TLabel;
  24.     PageProducer1: TPageProducer;
  25.     procedure BitBtn1Click(Sender: TObject);
  26.     procedure BitBtn2Click(Sender: TObject);
  27.     procedure FormShow(Sender: TObject);
  28.     procedure ComboBox1Change(Sender: TObject);
  29.     procedure PageProducer1HTMLTag(Sender: TObject; Tag: TTag;
  30.       const TagString: String; TagParams: TStrings;
  31.       var ReplaceText: String);
  32.   private
  33.     { Private declarations }
  34.     procedure SetFileToShow(Value: string);
  35.   public
  36.     { Public declarations }
  37.     property FileToShow: string write SetFileToShow;
  38.   end;
  39.  
  40. var
  41.   CCForm: TCCForm;
  42.  
  43. implementation
  44.  
  45. {$R *.DFM}
  46.  
  47. procedure TCCForm.SetFileToShow(Value: string);
  48. begin
  49.   Memo1.Lines.Clear;
  50.   Memo1.Lines.LoadFromFile(Value);
  51. end;
  52.  
  53. procedure TCCForm.BitBtn1Click(Sender: TObject);
  54. begin
  55.   Close;
  56. end;
  57.  
  58. procedure TCCForm.BitBtn2Click(Sender: TObject);
  59. var
  60.   F: TextFile;
  61.   i: integer;
  62. begin
  63.   { print memo.lines }
  64.   Printer.Title := 'Form Print Demo';
  65.   Printer.Canvas.Font.Name := ComboBox2.Text;
  66.   Printer.Canvas.Font.Size := 10;
  67.   AssignPrn(F);
  68.   Rewrite(F);
  69.   try
  70.     for i := 0 to Memo1.Lines.Count-1 do
  71.       Writeln(F, Memo1.Lines[i]);
  72.   finally
  73.     CloseFile(F);
  74.   end;
  75. end;
  76.  
  77. procedure TCCForm.FormShow(Sender: TObject);
  78. begin
  79.   { set screen elements }
  80.   ComboBox1.Items.Assign(Screen.Fonts);
  81.   ComboBox1.ItemIndex := ComboBox1.Items.IndexOf(Memo1.Font.Name);
  82.   ComboBox2.Items.Assign(Printer.Fonts);
  83.   ComboBox2.ItemIndex := ComboBox2.Items.IndexOf(Memo1.Font.Name);
  84.   Memo1.Text := PageProducer1.Content;
  85. end;
  86.  
  87. procedure TCCForm.ComboBox1Change(Sender: TObject);
  88. begin
  89.   Memo1.Font.Name := ComboBox1.Text;
  90.   ComboBox2.ItemIndex := ComboBox2.Items.IndexOf(Memo1.Font.Name);
  91. end;
  92.  
  93. procedure TCCForm.PageProducer1HTMLTag(Sender: TObject; Tag: TTag;
  94.   const TagString: String; TagParams: TStrings; var ReplaceText: String);
  95. begin
  96.   if Pos('Product', TagString) <> 0 then
  97.     ReplaceText := Format('%-*s', [Length(TagString)+3, Edit1.Text]);
  98.  
  99.   if Pos('Size', TagString) <> 0 then
  100.     ReplaceText := Format('%*s', [Length(TagString)+3, Edit2.Text]);
  101.  
  102.   if Pos('Date', TagString) <> 0 then
  103.     ReplaceText := Format('%-*s', [Length(TagString)+3, DateToStr(Date)]);
  104. end;
  105.  
  106. end.
  107.